﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="SysAdmin_User_List" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <script type="text/javascript">
        $(function () {
            $('#user_datagrid').datagrid({
                url: 'User/List.aspx?paramType=QueryList',
                fit: true,
                fitColumns: true,
                border: false,
                pagination: true,
                idField: 'ID',
                pageSize: 30,
                pageList: [10, 20, 30, 40, 50],
                sortName: 'text',
                sortOrder: 'asc',
                checkOnSelect: false,
                selectOnCheck: false,
                nowrap: false,
                frozenColumns: [[{
                    title: '编号',
                    field: 'id',
                    width: 150,
                    sortable: true,
                    checkbox: true
                }, {
                    title: '用户名',
                    field: 'userName',
                    width: 150,
                    sortable: true
                }]],
                columns: [[{
                    title: '真实姓名',
                    field: 'fullName',
                    width: 300
                }, {
                    title: '性别',
                    field: 'sex',
                    width: 300
                }, {
                    title: '生日',
                    field: 'temp_text',
                    width: 300
                }, {
                    title: '角色',
                    field: 'roleCode',
                    width: 300
                }, {
                    field: 'action',
                    title: '动作',
                    width: 100,
                    formatter: function (value, row, index) {
                        if (row.id == '0') {
                            return '系统角色';
                        } else {
                            return formatString('<img onclick="sysadmin_user_edit(\'{0}\');" src="{1}"/>&nbsp;<img onclick="sysadmin_user_del(\'{2}\');" src="{3}"/>', row.ID, 'Images/pencil.png', row.ID, 'Images/cancel.png');
                        }
                    }
                }]],
                toolbar: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        sysadmin_user_add();
                    }
                }, '-', {
                    text: '批量删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        sysadmin_user_remove();
                    }
                }, '-', {
                    text: '批量设置角色',
                    iconCls: 'icon-edit',
                    handler: function () {
                        sysadmin_user_modifyRole();
                    }
                }, '-']
            });
        });

        //添加用户
        function sysadmin_user_add() {

            $('#user_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');

            $('<div/>').dialog({
                href: 'User/Add.aspx',
                width: 520,
                height: 260,
                modal: true,
                title: '添加用户',
                buttons: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {

                        var d = $(this).closest('.window-body');
                        $('#admin_user_addForm').form('submit', {
                            url: 'User/List.aspx?paramType=AddModel',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        $('#user_datagrid').datagrid('load', {});
                                        d.dialog('destroy');
                                    }
                                    $.messager.show({
                                        title: '提示',
                                        msg: r.msg
                                    });
                                } catch (e) {
                                    $.messager.alert('提示', result);
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $(this).dialog('destroy');
                }
            });
        }

        //编辑用户
        function sysadmin_user_edit(user_key) {
            $('<div/>').dialog({
                href: 'User/Edit.aspx?user_key=' + user_key,
                width: 520,
                height: 260,
                modal: true,
                title: '用户编辑',
                buttons: [{
                    text: '编辑',
                    iconCls: 'icon-add',
                    handler: function () {
                        var d = $(this).closest('.window-body');
                        $('#admin_user_editForm').form('submit', {
                            url: 'User/List.aspx?paramType=UpdateModel',
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        d.dialog('destroy');
                                        $('#user_datagrid').datagrid('load', {});
                                    }
                                } catch (e) {

                                    $.messager.alert('提示', "编辑失败，请重试！");
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $(this).dialog('destroy');
                }
            });
        }

        //删除用户
        function sysadmin_user_del(user_key) {

            $.messager.confirm('提示', '你确定要删除该行数据么?', function (r) {
                if (r) {
                    $.ajax({
                        type: "POST",
                        url: 'User/List.aspx',
                        data: "paramType=DelModel&userCode=" + user_key,
                        dataType: "json",
                        success: function (msg) {
                            if (msg.success) {
                                $('#user_datagrid').datagrid('load', {});
                            }
                        },
                        error: function (e, ex) {
                            $.messager.alert('错误提示', '删除失败！');
                        }

                    });
                }
            });
        }

        //查询条件
        function sysadmin_user_search() {

        }

    </script>

    <div class="easyui-layout" data-options="fit : true,border : false">
        <div data-options="region:'north',title:'查询条件',border:false" style="height: 65px; overflow: hidden;" align="center">
            <form id="admin_yhgl_searchForm">
                <table class="tableForm" style="width: 100%">
                    <tr>
                        <th style="width: 170px;">检索用户名称(可模糊查询)</th>
                        <td>
                            <input id="user_name" name="user_name" style="width: 315px;" />
                        </td>
                        <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="sysadmin_role__search();">过滤条件</a> <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="document.getElementById('user_name').value = '';">清空条件</a></td>
                    </tr>
                </table>
            </form>
        </div>
        <div data-options="region:'center',border:false">
            <table id="user_datagrid"></table>
        </div>
    </div>
</body>
</html>
